import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from "@/views/Login.vue";
import Index from "@/views/Index.vue";
import About from "@/views/about/About.vue";
import User from "@/views/user/User"
import Car from "@/views/vips/CarMenagement"
import FrontUser from "@/views/vips/CustomerManagement"
import UserIntegral from "@/views/vips/PointsManagement"
import UserDetail from "@/views/vips/DetailManagement"
import Product from "@/views/product/Product";
import ProductType from "@/views/product/ProductType";
import Station from "@/views/store/StoreStation.vue";
import UserAddress from "@/views/vips/AddressManagement"
import Role from "@/views/user/Role.vue";
import StoreEvaluate from "@/views/store/StoreEvaluate.vue";
import ProductOrder from "@/views/order/OrderManagement"
import Menu from "@/views/menu/Menu.vue";
import CouponCodes from "@/views/store/couponCodes.vue";
import StoreLabels from "@/views/store/StoreLabels.vue";
import Store from "@/views/store/Store.vue";
import MoneyEcharts from "@/views/sale/MoneyEcharts.vue";
import StoreEcharts from "@/views/sale/StoreEcharts.vue";
import VIPEcharts from "@/views/sale/VIPEcharts.vue";
import ProductImage from "@/views/product/ProductImage";
import ProductReview from "@/views/product/ProductReview";
import ProductExamine from "@/views/examine/ProductExamine";
import Show from  "@/views/Show.vue";
Vue.use(VueRouter)


const routes = [
    {
        path: '/',
        name: 'home',
        redirect: "/login",
    },
    {
        path: "/login",
        name: "/Login",
        component: Login
    },
    {
        path: "/index",
        name: "/Index",
        component: Index,
        children: [
            //用户列表
            {
                path: "/User",
                name: "/User",
                component: User
            },
            //关于我们
            {
                path: "/About",
                name: "/About",
                component: About
            },
            //Vip管理-车辆管理
            {
                path: "/Car",
                name: "/Car",
                component: Car,
            },
            //Vip管理-客户管理
            {
                path: "/FrontUser",
                name: "/FrontUser",
                component: FrontUser,
            },
            //Vip管理-积分管理
            {
                path: "/UserIntegral",
                name: "/UserIntegral",
                component: UserIntegral,
            },
            //Vip管理-地址管理
            {
                path: "/UserAddress",
                name: "/UserAddress",
                component: UserAddress,
            },
            //Vip管理-明细管理
            {
                path: "/UserDetail",
                name: "/UserDetail",
                component: UserDetail,
            },

            //订单管理
            {
                path: "/ProductOrder",
                name: "/ProductOrder",
                component: ProductOrder,
            },
            //商品列表
            {
                path: "/Product",
                name: "/Product",
                component: Product,
            },
            //商品类型
            {
                path: "/ProductType",
                name: "/ProductType",
                component: ProductType,
            },
            //门店工位
            {
                path: "/Station",
                name: "/Station",
                component: Station,
            },
            //角色列表
            {
                path: "/Role",
                name: "/Role",
                component: Role
            },
            //门店评估
            {
                path: "/StoreEvaluate",
                name: "/StoreEvaluate",
                component: StoreEvaluate
            },
            //优惠券列表
            {
                path: "/CouponCodes",
                name: "/CouponCodes",
                component: CouponCodes
            },
            //门店标签
            {
                path: "/StoreLabels",
                name: "/StoreLabels",
                component: StoreLabels
            },
            //菜单权限管理
            {
                path: "/Menu",
                name: "/Menu",
                component: Menu
            },
            {
                path:"/Store",
                name: "/Store",
                component: Store
            },
            {
                path:"/MoneyEcharts",
                name: "/MoneyEcharts",
                component: MoneyEcharts
            },
            {
                path:"/StoreEcharts",
                name: "/StoreEcharts",
                component: StoreEcharts
            },
            {
                path:"/VIPEcharts",
                name: "/VIPEcharts",
                component: VIPEcharts
            },
            {
                path:"/ProductImage",
                name: "/ProductImage",
                component: ProductImage
            },
            {
                path:"/ProductReview",
                name: "/ProductReview",
                component: ProductReview
            },
            {
                path:"/ProductExamine",
                name: "/ProductExamine",
                component: ProductExamine
            },
            {
                path:"/show",
                name: "/Show",
                component: Show
            },

        ]
    },

]

const router = new VueRouter({
    routes
})

// 获取原型对象push函数
const originalPush = VueRouter.prototype.push

// 获取原型对象replace函数
const originalReplace = VueRouter.prototype.replace

// 修改原型对象中的push函数
VueRouter.prototype.push = function push(location) {
    return originalPush.call(this, location).catch(err => err)
}

// 修改原型对象中的replace函数
VueRouter.prototype.replace = function replace(location) {
    return originalReplace.call(this, location).catch(err => err)
}

//前置路由守卫
router.beforeEach((to, from, next) => {
    let path = to.path;
    if (path === "/" || path === "/login") {
        next();
    } else {
        let token = sessionStorage.getItem("token");
        if (token) {
            next();
        } else {
            next("/login");
        }
    }
})

export default router
